<?php
function getPagingLink($res, $rowsPerPage, $pageNum,$self)
{
		
		$numrows = mysql_num_rows($res);
			// how many pages we have when using paging?
		$maxPage = ceil($numrows/$rowsPerPage);
		
		// print the link to access each page
		//$self = $_SERVER['PHP_SELF'];
		$nav = '';
		if($maxPage <= 9)
		{
			for($page = 1; $page <= $maxPage; $page++)
			{
				if ($page == $pageNum)
				{
					 $nav .= " <strong>$page</strong> ";   // no need to create a link to current page
				}
				else
				{	
					$nav .= " <a href=\"$self&page=$page\">$page</a> ";
				}
			}
		}
		else
		{
			if($pageNum <= 6)
			{
				for($page = 1; $page <= 6; $page++)
				{
					if($page == $pageNum)
					{
						$nav .= "<strong>$page</strong>";
					}
					else
					{
						$nav .= " <a href=\"$self&page=$page\">$page</a> ";
					}
				}
				$last2 = $maxPage - 1;
				$nav .= "&nbsp;...&nbsp;";
				for($page = $last2; $page <= $maxPage; $page++)
				{
					$nav .= " <a href=\"$self&page=$page\">$page</a> ";
				}
			}
			else if($maxPage - $pageNum <= 3)
			{
				for($page = 1; $page <= 2; $page++)
				{
					$nav .= " <a href=\"$self&page=$page\">$page</a> ";
				}
				$nav .= "&nbsp;...&nbsp;";
				for($page = $maxPage-4; $page <= $maxPage; $page++)
				{
					if($page == $pageNum)
					{
						$nav .= "<strong>$page</strong>";
					}
					else
					{
						$nav .= " <a href=\"$self&page=$page\">$page</a> ";
					}
				}
			}
			else
			{
				for($page = 1; $page <= 2; $page++)
				{
					$nav .= " <a href=\"$self&page=$page\">$page</a> ";
				}
				$nav .= "&nbsp;...&nbsp;";
				for($page = $pageNum-1; $page <= $pageNum+1; $page++)
				{
					if($page == $pageNum)
					{
						$nav .= "<strong>$page</strong>";
					}
					else
					{
						$nav .= " <a href=\"$self&page=$page\">$page</a> ";
					}
				}
				$nav .= "&nbsp;...&nbsp;";
				$last2 = $maxPage - 1;
				for($page = $last2; $page <= $maxPage; $page++)
				{
					$nav .= " <a href=\"$self&page=$page\">$page</a> ";
				}
			}			
			
		}	
		
		// creating previous and next link
		// plus the link to go straight to
		// the first and last page
		
		
		if ($pageNum > 1)
		{
			$page = $pageNum - 1;
			$prev = " <a href=\"$self&page=$page\">Prev</a> ";
			
			$first = " <a href=\"$self&page=1\">First</a> ";
		} 
		else
		{
			$prev  = '&nbsp;'; // we're on page one, don't print previous link
			$first = '&nbsp;'; // nor the first page link
		}
		
		if ($pageNum < $maxPage)
		{
				$page = $pageNum + 1;
			//echo $page;
			$next = " <a href=\"$self&page=$page\">Next</a> ";
			
			$last = " <a href=\"$self&page=$maxPage\">Last</a> ";
		} 
		else
		{
			$next = '&nbsp;'; // we're on the last page, don't print next link
			$last = '&nbsp;'; // nor the last page link
		}
		
		?>
        <div class="pagerDRUPAL">
        <div class="pager-list">
        <?php
		// print the navigation link
		echo $first . $prev . $nav . $next . $last;
		?>
        </div></div>
        
        <?php

} 


?>

	 
	 